package com.ap.autobase.services.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ap.autobase.domain.Order;
import com.ap.autobase.repository.OrderDao;
import com.ap.autobase.services.OrderService;
import com.ap.autobase.utils.Identifier;

@Service
@Transactional
public class OrderServiceImpl implements OrderService {

	@Autowired
	OrderDao orderDao;

	public void addOrder(Order order) {
		int id = order.getId();
		Identifier identificator = new Identifier();
		order.setIdentificator(identificator.createIdentifier(id));
		orderDao.save(order);
	}

	public void removeOrder(Order order) {
		orderDao.delete(order);
	}

	public void updateOrder(Order order) {
		orderDao.update(order);

	}

	@Override
	public Order getOrderById(int id) {
		return orderDao.getOrderById(id);
	}

	@Override
	public Order getOrderByIdentificator(String identificator) {
		return orderDao.getOrderByIdentificator(identificator);		
	}

}
